home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / emsif24a.zip / EMSTEST.C < prev    next >
C/C++ Source or Header  |  1993-06-16  |  65KB  |  1,593 lines

  1. /***************************************************************************
  2. *   emstest.c                                                              *
  3. *   MODULE:  EMSIF                                                         *
  4. *   OS:      DOS                                                           *
  5. *   VERSION: 1.2                                                           *
  6. *   DATE:    06/15/93                                                      *
  7. *                                                                          *
  8. *   Copyright (c) 1991, 1993 James W. Birdsall. All Rights Reserved.       *
  9. *                                                                          *
  10. *   Requires emsif.h, testutil.h, and emstest.h to compile.                *
  11. *   Compiles under Borland C++ 2.0, TC 2.0, MSC/C++ 7.0, and               *
  12. *    MS Visual C++ 1.0.                                                    *
  13. *                                                                          *
  14. *   Regression test and example for EMSIF.                                 *
  15. *                                                                          *
  16. *   This is part one of the regression tester and example for EMSIF.       *
  17. *   The other parts are named EMSTEST2.C and EMSTEST3.C. All three parts   *
  18. *   must be compiled and linked together along with the appropriate EMSIF  *
  19. *   library and a utilities file TESTUTIL.C to produce the tester          *
  20. *   executable. This program compiles under tiny, small, medium, compact,  *
  21. *   large, and huge models. Note that it doesn't quite fit into tiny       *
  22. *   model; the tiny model tester is actually three executables. The        *
  23. *   compact model under MSC 7.0 suffers from the same problem. When        *
  24. *   compiling for these configurations, one of the symbols PASS1, PASS2,   *
  25. *   or PASS3 must be defined. See the example makefiles for further        *
  26. *   details on what needs to be linked with what to produce these          *
  27. *   executables.                                                           *
  28. *                                                                          *
  29. *   To use this tester: just run it. It requires no arguments and produces *
  30. *   output on stdout. It performs nearly 200 tests and parts of it run     *
  31. *   quite fast, even on an original IBM PC/XT (4.77 MHz). If you want to   *
  32. *   actually read the output, you should redirect the output to a file.    *
  33. *   If you just want to see whether the tests all pass, simply run it --   *
  34. *   if a test fails, execution aborts immediately.                         *
  35. *                                                                          *
  36. *   Certain types of failure may cause EMSTEST to not deallocate EMS or    *
  37. *   conventional memory that it has allocated. This should only occur if   *
  38. *   the library itself is malfunctioning (which should never happen to     *
  39. *   you, only to me!) or if you are trying a different compiler or         *
  40. *   unsupported memory model and the compiler and library are therefore    *
  41. *   not communicating properly. It may also happen if you press control-   *
  42. *   break.                                                                 *
  43. *                                                                          *
  44. *   Turbo C and older versions of Turbo C++ do not have the _fmemcmp() and *
  45. *   _fmemset() functions; I don't know about older versions of MSC. If     *
  46. *   your compiler does not have these functions, define the symbol         *
  47. *   NO_FFUNC and functions in the ancillary file TESTUTIL.C will be used   *
  48. *   instead.                                                               *
  49. *                                                                          *
  50. ***************************************************************************/
  51.  
  52. /*
  53. ** system includes <>
  54. */
  55.  
  56. #include <stdio.h>
  57. #include <stdlib.h>
  58. #include <string.h>
  59.  
  60.  
  61. /*
  62. ** custom includes ""
  63. */
  64.  
  65. #include "testutil.h"
  66.  
  67. #include "emsif.h"
  68. #include "emstest.h"
  69.  
  70.  
  71. /*
  72. ** local #defines
  73. */
  74.  
  75. /*
  76. ** misc: copyright strings, version macros, etc.
  77. */
  78.  
  79. /*
  80. ** typedefs
  81. */
  82.  
  83. /*
  84. ** global variables
  85. */
  86.  
  87. int testno = 1;                     /* number of test currently being done  */
  88. unsigned char far *frameptr[4];     /* pointers to EMS frames               */
  89. char *gblmsg = "";                  /* msg to be printed in test header     */
  90.  
  91.  
  92. /*
  93. ** static globals
  94. */
  95.  
  96. /*
  97. ** function prototypes
  98. */
  99.  
  100. /*
  101. ** functions
  102. */
  103.  
  104.  
  105. /***************************************************************************
  106. *   FUNCTION: MAIN                                                         *
  107. *                                                                          *
  108. *   DESCRIPTION:                                                           *
  109. *                                                                          *
  110. *       The master function.                                               *
  111. *                                                                          *
  112. *   ENTRY:                                                                 *
  113. *                                                                          *
  114. *       None.                                                              *
  115. *                                                                          *
  116. *   EXIT:                                                                  *
  117. *                                                                          *
  118. *       Void.                                                              *
  119. *                                                                          *
  120. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  121. *                                                                          *
  122. ***************************************************************************/
  123. main()
  124. {
  125.     int status;                     /* return status from library functions */
  126.  
  127.     /*
  128.     ** check initialization test
  129.     */
  130.     TESTHEADER();
  131.     printf("Making a call to EMMgetversion() before calling EMMlibinit().\n");
  132.     printf("The call should fail.\n");
  133.     EMMgetversion();
  134.     nofailcheck("EMMgetversion()", (int) _EMMerror, NULL, 0, 0);
  135.     weirdcodechk("EMMgetversion()", EMM_NOINIT, NULL, 0, 0);
  136.     TESTTAILER();
  137.  
  138.  
  139.     /*
  140.     ** initialize EMSIF
  141.     */
  142.     TESTHEADER();
  143.     printf("Calling EMMlibinit().\n");
  144.     printf("Should succeed if and only if Expanded Memory Manager for EMS version 3.0 or\n");
  145.     printf(" greater is present.\n");
  146.     status = EMMlibinit();
  147.     switch (status)
  148.     {
  149.         case EMMOOPS:
  150.             printf("EMMlibinit() failed, code 0x%X.\n",
  151.                                                     (unsigned int) _EMMerror);
  152.             exit(3);
  153.             break;
  154.  
  155.         case NOEMM:
  156.             printf("EMMlibinit() did not find an Expanded Memory Manager.\n");
  157.             exit(3);
  158.             break;
  159.  
  160.         case 0:
  161.             printf("EMMlibinit() returned OK.\n");
  162.             weirdcodechk("EMMlibinit()", 0, NULL, 0, 0);
  163.             break;
  164.  
  165.         default:
  166.             printf("EMMlibinit() returned strange value %d.\n", status);
  167.             exit(3);
  168.             break;
  169.     }
  170.     TESTTAILER();
  171.  
  172. /*
  173. ** The following section of code is included only in the first tiny-model
  174. ** executable and in non-tiny-model executables.
  175. */
  176. #ifndef PASS2
  177. #ifndef PASS3
  178.  
  179.     /*
  180.     ** test version call
  181.     */
  182.     TESTHEADER();
  183.     printf("Testing EMMgetversion().\n");
  184.     printf("Results should match value in _EMMversion.\n");
  185.     status = EMMgetversion();
  186.     weirdcodechk("EMMgetversion()", 0, NULL, 0, 0);
  187.     if (status != (int) _EMMversion)
  188.     {
  189.         printf("EMMgetversion() [0x%X] and _EMMversion [0x%X] differ.\n",
  190.                                            status, (unsigned int) _EMMversion);
  191.         exit(3);
  192.     }
  193.     printf("EMS version %d.%d.\n", ((status >> 4) & 0xF), (status & 0xF));
  194.     TESTTAILER();
  195.  
  196.  
  197.     /*
  198.     ** test allocation functions
  199.     */
  200.     do_alloc_tests(1L);
  201.     do_alloc_tests(16384L);
  202.     do_alloc_tests(55555L);
  203.     do_alloc_tests(0L);
  204.  
  205. #endif /* !PASS3 */
  206. #endif /* !PASS2 */
  207.  
  208.     /*
  209.     ** test frame functions -- included in all executables
  210.     */
  211.     do_frame_tests();
  212.  
  213. /*
  214. ** The following section of code is included only in the first tiny-model
  215. ** executable and in non-tiny-model executables.
  216. */
  217. #ifndef PASS2
  218. #ifndef PASS3
  219.  
  220.     /*
  221.     ** test name functions
  222.     */
  223.     do_name_tests();
  224.  
  225.     /*
  226.     ** do mapping tests
  227.     */
  228.     do_map_tests();
  229.  
  230.     /*
  231.     ** do realloc tests
  232.     */
  233.     do_realloc_tests();
  234.  
  235.     /*
  236.     ** test the save/restore facility
  237.     */
  238.     do_sr_tests();
  239.  
  240. #endif /* !PASS3 */
  241. #endif /* !PASS2 */
  242.  
  243. /*
  244. ** The following section of code is included only in the second tiny-model
  245. ** executable and in non-tiny-model executables.
  246. */
  247. #ifndef PASS1
  248. #ifndef PASS3
  249.  
  250.     /*
  251.     ** test copies of <= one page, frame caching on
  252.     */
  253.     gblmsg = "  SHORT COPY TESTS";
  254.     do_shortcopy_tests();
  255.     gblmsg = "";
  256.  
  257.     /*
  258.     ** test frame cache control
  259.     */
  260.     TESTHEADER();
  261.     printf("Testing frame caching enable/disable.\n");
  262.     if (_EMMframecache != 0)
  263.     {
  264.         printf("Frame caching is supposed to be off by default, seems to ");
  265.         printf("be on.\n");
  266.         exit(3);
  267.     }
  268.     _EMMenc();
  269.     weirdcodechk("_EMMenc()", 0, NULL, 0, 0);
  270.     if (_EMMframecache == 0)
  271.     {
  272.         printf("_EMMenc() did not enable frame caching.\n");
  273.         exit(3);
  274.     }
  275.     _EMMdisc();
  276.     weirdcodechk("_EMMdisc()", 0, NULL, 0, 0);
  277.     if (_EMMframecache != 0)
  278.     {
  279.         printf("_EMMdisc() did not disable frame caching.\n");
  280.         exit(3);
  281.     }
  282.     printf("Flag and function calls correspond OK.\n");
  283.     TESTTAILER();
  284.  
  285.     /*
  286.     ** test copies of <= one page, frame caching on
  287.     */
  288.     _EMMenc();
  289.     gblmsg = "  SHORT COPY TESTS WITH FRAME CACHING ON";
  290.     do_shortcopy_tests();
  291.     _EMMdisc();
  292.  
  293. #endif /* !PASS3 */
  294.  
  295. /*
  296. ** The following section of code is included only in the third tiny-model
  297. ** executable and in non-tiny-model executables.
  298. */
  299. #ifndef PASS2
  300.  
  301.     /*
  302.     ** test copies of > 1 page, frame caching off
  303.     */
  304.     _EMMdisc();
  305.     gblmsg = "  LONG COPY TESTS";
  306.     do_longcopy_tests();
  307.  
  308.     /*
  309.     ** test copies of > 1 page, frame caching on
  310.     */
  311.     _EMMenc();
  312.     gblmsg = "  LONG COPY TESTS WITH FRAME CACHING ON";
  313.     do_longcopy_tests();
  314.     gblmsg = "";
  315.     _EMMdisc();
  316.  
  317. #endif /* !PASS2 */
  318. #endif /* !PASS1 */
  319.  
  320.     /* end and cleanup */
  321.     printf(">>>END\n");
  322.     printf("All tests succeeded.\n");
  323.  
  324.     exit(0);
  325. } /* end of main() */
  326.  
  327.  
  328. /***************************************************************************
  329. *   FUNCTION: DO_FRAME_TESTS                                               *
  330. *                                                                          *
  331. *   DESCRIPTION:                                                           *
  332. *                                                                          *
  333. *       This function tests EMSIF calls EMMgetnumframe(),                  *
  334. *       EMMgetframeaddr(), and EMMgetsinfraddr().                          *
  335. *                                                                          *
  336. *   ENTRY:                                                                 *
  337. *                                                                          *
  338. *       Void.                                                              *
  339. *                                                                          *
  340. *   EXIT:                                                                  *
  341. *                                                                          *
  342. *       Void.                                                              *
  343. *                                                                          *
  344. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  345. *                                                                          *
  346. *       Fills in the frameptr[] global array.                              *
  347. *                                                                          *
  348. ***************************************************************************/
  349. void do_frame_tests(void)
  350. {
  351.     frameinfo *framebuf;
  352.     int frames;
  353.     int status;
  354.     int loop;
  355.     unsigned int segaddr;
  356.  
  357.     /* set header */
  358.     gblmsg = "  FRAME TESTS";
  359.  
  360.     /* get number of frames */
  361.     TESTHEADER();
  362.     printf("Getting number of frames with EMMgetnumframe().\n");
  363.     if (_EMMversion < 0x40)
  364.     {
  365.         printf("Should be exactly 4.\n");
  366.     }
  367.     else
  368.     {
  369.         printf("Should be 4 or more.\n");
  370.     }
  371.     frames = EMMgetnumframe();
  372.     weirdcodechk("EMMgetnumframe()", 0, NULL, 0, 0);
  373.     if (frames < 4)
  374.     {
  375.         printf("EMMgetnumframe() returned OK but indicates only %d frames.\n",
  376.                                                                        frames);
  377.         exit(3);
  378.     }
  379.     if ((_EMMversion < 0x40) && (frames != 4))
  380.     {
  381.         printf("EMMgetnumframe() returned OK but indicates wrong number of\n");
  382.         printf("   frames (%d) for this version.\n", frames);
  383.         exit(3);
  384.     }
  385.     printf("EMMgetnumframe() returned OK, %d frames.\n", frames);
  386.     TESTTAILER();
  387.  
  388.     /* allocate memory for frame address buffer */
  389.     framebuf = (frameinfo *) calloc(frames, sizeof(frameinfo));
  390.     if (framebuf == (frameinfo *) NULL)
  391.     {
  392.         printf("OOPS! Couldn't allocate a buffer. Aborting.\n");
  393.         exit(3);
  394.     }
  395.  
  396.     /* get frame segment addresses */
  397.     TESTHEADER();
  398.     printf("Getting frame address info with EMMgetframeaddr().\n");
  399.     printf("Should succeed.\n");
  400.     status = EMMgetframeaddr(framebuf);
  401.     TRIPLECHECK("EMMgetframeaddr()", status, 0, framebuf, 0, 0);
  402.     printf("EMMgetframeaddr() returned OK, checking info returned...\n");
  403.     for (loop = 0; loop < frames; loop++)
  404.     {
  405.         /* check for valid frame number */
  406.         if (framebuf[loop].frameno >= frames)
  407.         {
  408.             printf("Frame number in slot %d is bad (%u).\n", loop,
  409.                                                        framebuf[loop].frameno);
  410.             free(framebuf);
  411.             exit(3);
  412.         }
  413.         /* check that frame segment address is on a page (16K) boundary */
  414.         if ((framebuf[loop].segaddr & 0x3FF) != 0)
  415.         {
  416.             printf(
  417.              "Frame segment %u, slot %d, frame number %u, not page aligned.\n",
  418.              framebuf[loop].segaddr, loop, framebuf[loop].frameno);
  419.             free(framebuf);
  420.             exit(3);
  421.         }
  422.         /* if one of frames 0-3, save the address */
  423.         if (framebuf[loop].frameno < 4)
  424.         {
  425.             frameptr[framebuf[loop].frameno] = (unsigned char far *)
  426.                                               MK_FP(framebuf[loop].segaddr, 0);
  427.         }
  428.     }
  429.     printf("Info returned checks out OK.\n");
  430.     TESTTAILER();
  431.  
  432.     /* now test EMMgetsinfraddr() */
  433.     TESTHEADER();
  434.     printf("Testing EMMgetsinfraddr() against data from EMMgetframeaddr().\n");
  435.     printf("Should succeed.\n");
  436.     /* loop through framebuf, calling EMMgetsinfraddr() on each */
  437.     for (loop = 0; loop < frames; loop++)
  438.     {
  439.         segaddr = EMMgetsinfraddr(framebuf[loop].frameno);
  440.         weirdcodechk("EMMgetsinfraddr()", 0, framebuf, 0, 0);
  441.         if (segaddr != framebuf[loop].segaddr)
  442.         {
  443.             printf("EMMgetsinfraddr(%u) succeeded but returned %u, not %u.\n",
  444.                       framebuf[loop].frameno, segaddr, framebuf[loop].segaddr);
  445.             free(framebuf);
  446.             exit(3);
  447.         }
  448.     }
  449.     printf("EMMgetsinfraddr() returned all addresses OK.\n");
  450.     TESTTAILER();
  451.  
  452.     /* clean up */
  453.     free(framebuf);
  454.     gblmsg = "";
  455.  
  456.     return;
  457. } /* end of do_frame_tests() */
  458.  
  459.  
  460. /*
  461. ** The following section of code is included only in the first tiny-model
  462. ** executable and in non-tiny-model executables.
  463. */
  464. #ifndef PASS2
  465. #ifndef PASS3
  466.  
  467.  
  468. /***************************************************************************
  469. *   FUNCTION: DO_ALLOC_TESTS                                               *
  470. *                                                                          *
  471. *   DESCRIPTION:                                                           *
  472. *                                                                          *
  473. *       This function tests EMSIF calls EMMcoreleft(), EMMalloc(), and     *
  474. *       EMMfree(). Don't bother testing EMMallocpages() -- if EMMalloc()   *
  475. *       works, it's only because EMMallocpages() (used internally) works.  *
  476. *                                                                          *
  477. *   ENTRY:                                                                 *
  478. *                                                                          *
  479. *       bytes - number of bytes of EMS to try to allocate.                 *
  480. *                                                                          *
  481. *   EXIT:                                                                  *
  482. *                                                                          *
  483. *       Void.                                                              *
  484. *                                                                          *
  485. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  486. *                                                                          *
  487. ***************************************************************************/
  488. void do_alloc_tests(unsigned long bytes)
  489. {
  490.     unsigned long emsfree, emsfree2;
  491.     unsigned long pagelen;
  492.     int handle;
  493.  
  494.     /* set header */
  495.     gblmsg = "  ALLOCATION TESTS";
  496.  
  497.     /* get bytes value rounded up to nearest page, or 1 page if bytes == 0 */
  498.     if (bytes != 0L)
  499.     {
  500.         pagelen = bytes + 16383L;
  501.         pagelen &= 0xFFFFC000L;
  502.     }
  503.     else
  504.     {
  505.         pagelen = 16384L;
  506.     }
  507.  
  508.     /* test coreleft */
  509.     TESTHEADER();
  510.     printf("Testing EMMcoreleft().\n");
  511.     printf("Result should be multiple of 16384.\n");
  512.     emsfree = test_EMMcoreleft();
  513.     printf("EMMcoreleft() returned OK, shows %lu bytes (%lu pages) free.\n",
  514.                                                   emsfree, (emsfree / 16384L));
  515.     TESTTAILER();
  516.  
  517.     /* make sure enough free */
  518.     if (emsfree < (MINFREE * 16384L))
  519.     {
  520.         printf("Insufficient free EMS to perform all tests. Aborting.\n");
  521.         exit(1);
  522.     }
  523.  
  524.     /* test allocation */
  525.     TESTHEADER();
  526.     printf("Testing EMMalloc(%lu).\n", bytes);
  527.     printf("Should succeed. Free EMS should drop by %lu bytes (%lu pages).\n",
  528.                                                   pagelen, (pagelen / 16384L));
  529.     handle = test_EMMalloc(bytes);
  530.     printf("EMMalloc() returned OK.\n");
  531.     emsfree2 = test_EMMcoreleft();
  532.     printf("EMMcoreleft() returned OK, shows %lu bytes (%lu pages) free.\n",
  533.                                                 emsfree2, (emsfree2 / 16384L));
  534.     if ((emsfree - emsfree2) != pagelen)
  535.     {
  536.         printf("EMMalloc(%lu) caused free to drop weirdly from %lu to %lu.\n",
  537.                                                      bytes, emsfree, emsfree2);
  538.         EMMfree(handle);
  539.         exit(3);
  540.     }
  541.     TESTTAILER();
  542.  
  543.     /* test free */
  544.     TESTHEADER();
  545.     printf("Testing EMMfree() on handle just returned by EMMalloc().\n");
  546.     printf(
  547.         "Should succeed. Free EMS should increase by %lu bytes (%lu pages).\n",
  548.         pagelen, (pagelen / 16384L));
  549.     test_EMMfree(handle);
  550.     printf("EMMfree() returned OK.\n");
  551.     emsfree2 = test_EMMcoreleft();
  552.     printf("EMMcoreleft() returned OK, shows %lu bytes (%lu pages) free.\n",
  553.                                                 emsfree2, (emsfree2 / 16384L));
  554.     if (emsfree2 != emsfree)
  555.     {
  556.         printf("Freeing handle returned by EMMalloc() did not restore\n");
  557.         printf("   free EMS count -- was %lu originally, now %lu.\n", emsfree,
  558.                                                                      emsfree2);
  559.         exit(3);
  560.     }
  561.     TESTTAILER();
  562.  
  563.     gblmsg = "";
  564.  
  565.     return;
  566. } /* end of do_alloc_tests() */
  567.  
  568.  
  569. /***************************************************************************
  570. *   FUNCTION: DO_NAME_TESTS                                                *
  571. *                                                                          *
  572. *   DESCRIPTION:                                                           *
  573. *                                                                          *
  574. *       This function tests EMSIF calls EMMgetname() and EMMsetname().     *
  575. *                                                                          *
  576. *   ENTRY:                                                                 *
  577. *                                                                          *
  578. *       Void.                                                              *
  579. *                                                                          *
  580. *   EXIT:                                                                  *
  581. *                                                                          *
  582. *       Void.                                                              *
  583. *                                                                          *
  584. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  585. *                                                                          *
  586. ***************************************************************************/
  587. void do_name_tests(void)
  588. {
  589.     char name[9];
  590.     int handle, status;
  591.  
  592.     /* set header */
  593.     gblmsg = "  NAME TESTS";
  594.  
  595.     TESTHEADER();
  596.     printf("Testing EMMsetname() and EMMgetname().\n");
  597.     if (_EMMversion < 0x40)
  598.     {
  599.         printf(
  600.               "EMMsetname() should fail, EMMgetname() return empty buffer.\n");
  601.     }
  602.     else
  603.     {
  604.         printf("Should succeed.\n");
  605.     }
  606.     /* allocate some EMS to assign a name to */
  607.     handle = test_EMMalloc(16384);
  608.     printf("Calling EMMsetname() with name ABCDEFGH.\n");
  609.     status = EMMsetname(handle, "ABCDEFGH");
  610.     if (_EMMversion < 0x40)
  611.     {
  612.         nofailcheck("EMMsetname()", status, NULL, handle, 0);
  613.         weirdretchk("EMMsetname()", status, NULL, handle, 0);
  614.         weirdcodechk("EMMsetname()", EMM_BADVERS, NULL, handle, 0);
  615.         printf("EMMsetname() failed OK.\n");
  616.     }
  617.     else
  618.     {
  619.         TRIPLECHECK("EMMsetname()", status, 0, NULL, handle, 0);
  620.         printf("EMMsetname() succeeded.\n");
  621.     }
  622.     printf("Now calling EMMgetname().\n");
  623.     status = EMMgetname(handle, name);
  624.     TRIPLECHECK("EMMgetname()", status, 0, NULL, handle, 0);
  625.     if (_EMMversion < 0x40)
  626.     {
  627.         if (farmemcheck((unsigned char far *) name, 9, '\0') != 0)
  628.         {
  629.             printf("A character in name is not null.\n");
  630.             EMMfree(handle);
  631.             exit(3);
  632.         }
  633.     }
  634.     else
  635.     {
  636.         if (strcmp(name, "ABCDEFGH") != 0)
  637.         {
  638.             printf("Got name %s back.\n", name);
  639.             EMMfree(handle);
  640.             exit(3);
  641.         }
  642.     }
  643.     printf("EMMgetname() succeeded.\n");
  644.     test_EMMfree(handle);
  645.     TESTTAILER();
  646.  
  647.     gblmsg = "";
  648.  
  649.     return;
  650. } /* end of do_name_tests() */
  651.  
  652.  
  653. /***************************************************************************
  654. *   FUNCTION: DO_MAP_TESTS                                                 *
  655. *                                                                          *
  656. *   DESCRIPTION:                                                           *
  657. *                                                                          *
  658. *       This function tests EMSIF call EMMmappage().                       *
  659. *                                                                          *
  660. *   ENTRY:                                                                 *
  661. *                                                                          *
  662. *       Void.                                                              *
  663. *                                                                          *
  664. *   EXIT:                                                                  *
  665. *                                                                          *
  666. *       Void.                                                              *
  667. *                                                                          *
  668. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  669. *                                                                          *
  670. ***************************************************************************/
  671. void do_map_tests(void)
  672. {
  673.     int handle1, handle2;
  674.     int loop;
  675.     int status;
  676.  
  677.     /* set header */
  678.     gblmsg = "  MAPPING TESTS";
  679.  
  680.     /* first, allocate some EMS to map */
  681.     handle1 = test_EMMallocpages(6);
  682.     handle2 = test_EMMallocpages(2);
  683.  
  684.     /* initial test of EMMmappage() */
  685.     TESTHEADER();
  686.     printf("Calling EMMmappage(frameno = 0, first handle, logpage = 0).\n");
  687.     printf("Should succeed.\n");
  688.     test_EMMmappage(0, handle1, 0);
  689.     printf("EMMmappage() returned OK.\n");
  690.     TESTTAILER();
  691.  
  692.     /* calling EMMmappage() with a bad logical page number */
  693.     TESTHEADER();
  694.     printf("Calling EMMmappage(frameno = 0, first handle, logpage = 6).\n");
  695.     printf("Should fail.\n");
  696.     status = EMMmappage(0, handle1, 6);
  697.     nofailcheck("EMMmappage()", status, NULL, handle1, handle2);
  698.     weirdretchk("EMMmappage()", status, NULL, handle1, handle2);
  699.     weirdcodechk("EMMmappage()", EMM_BADLOGPAGE, NULL, handle1, handle2);
  700.     printf("EMMmappage() failed OK.\n");
  701.     TESTTAILER();
  702.  
  703.     TESTHEADER();
  704.     printf("Writing data pattern to page 0, first handle... ");
  705.     FMEMSET(frameptr[0], 0, 16384);
  706.     printf("Verifying... ");
  707.     if (farmemcheck(frameptr[0], 16384, 0) != 0)
  708.     {
  709.         printf("Verify failed!\n");
  710.         test_EMMfree(handle1);
  711.         test_EMMfree(handle2);
  712.         exit(3);
  713.     }
  714.     printf("OK.\n");
  715.     printf("Calling EMMmappage(frameno = 0, first handle, logpage = 1).\n");
  716.     test_EMMmappage(0, handle1, 1);
  717.     printf("EMMmappage() returned OK.\n");
  718.     printf("Writing data pattern to page 1, first handle... ");
  719.     FMEMSET(frameptr[0], 1, 16384);
  720.     printf("Verifying... ");
  721.     if (farmemcheck(frameptr[0], 16384, 1) != 0)
  722.     {
  723.         printf("Verify failed!\n");
  724.         test_EMMfree(handle1);
  725.         test_EMMfree(handle2);
  726.         exit(3);
  727.     }
  728.     printf("OK.\n");
  729.     printf("Now mapping page 0 back, see if it's still OK.\n");
  730.     test_EMMmappage(0, handle1, 0);
  731.     printf("EMMmappage() returned OK, verifying contents... ");
  732.     if (farmemcheck(frameptr[0], 16384, 0) != 0)
  733.     {
  734.         printf("Verify failed!\n");
  735.         test_EMMfree(handle1);
  736.         test_EMMfree(handle2);
  737.         exit(3);
  738.     }
  739.     printf("OK.\n");
  740.     printf("EMMmappage() looks like it's doing something.\n");
  741.     TESTTAILER();
  742.  
  743.     TESTHEADER();
  744.     printf("Testing mapping of all frames...\n");
  745.     printf("Filling rest of allocated pages with unique patterns... ");
  746.     for (loop = 2; loop < 6; loop++)
  747.     {
  748.         test_EMMmappage(0, handle1, loop);
  749.         FMEMSET(frameptr[0], loop, 16384);
  750.         if (farmemcheck(frameptr[0], 16384, (unsigned char) loop) != 0)
  751.         {
  752.             printf("Verify failed on handle 1, page %d.\n", loop);
  753.             test_EMMfree(handle1);
  754.             test_EMMfree(handle2);
  755.             exit(3);
  756.         }
  757.     }
  758.     test_EMMmappage(0, handle2, 0);
  759.     FMEMSET(frameptr[0], 0x10, 16384);
  760.     if (farmemcheck(frameptr[0], 16384, 0x10) != 0)
  761.     {
  762.         printf("Verify failed on handle 2, page 0!\n");
  763.         test_EMMfree(handle1);
  764.         test_EMMfree(handle2);
  765.         exit(3);
  766.     }
  767.     test_EMMmappage(0, handle2, 1);
  768.     FMEMSET(frameptr[0], 0x11, 16384);
  769.     if (farmemcheck(frameptr[0], 16384, 0x11) != 0)
  770.     {
  771.         printf("Verify failed on handle 2, page 1!\n");
  772.         test_EMMfree(handle1);
  773.         test_EMMfree(handle2);
  774.         exit(3);
  775.     }
  776.     printf("Done.\n");
  777.     printf("Mapping handle 1 pages 0-3 in frames 0-3 respectively... ");
  778.     for (loop = 0; loop < 4; loop++)
  779.     {
  780.         test_EMMmappage(loop, handle1, loop);
  781.     }
  782.     printf("Done.\n");
  783.     printf("Verifying contents... ");
  784.     for (loop = 0; loop < 4; loop++)
  785.     {
  786.         if (farmemcheck(frameptr[loop], 16384, (unsigned char) loop) != 0)
  787.         {
  788.             printf("Verify failed for frame %d.\n", loop);
  789.             test_EMMfree(handle1);
  790.             test_EMMfree(handle2);
  791.             exit(3);
  792.         }
  793.     }
  794.     printf("OK.\n");
  795.     printf("Mapping handle 1 pages 0-3 in frames 0-3 in reverse... ");
  796.     for (loop = 0; loop < 4; loop++)
  797.     {
  798.         test_EMMmappage(loop, handle1, (3 - loop));
  799.     }
  800.     printf("Done.\n");
  801.     printf("Verifying contents... ");
  802.     for (loop = 0; loop < 4; loop++)
  803.     {
  804.         if (farmemcheck(frameptr[loop], 16384, (unsigned char)(3 - loop)) != 0)
  805.         {
  806.             printf("Verify failed for frame %d.\n", loop);
  807.             test_EMMfree(handle1);
  808.             test_EMMfree(handle2);
  809.             exit(3);
  810.         }
  811.     }
  812.     printf("OK.\n");
  813.     printf(
  814.       "Mapping handle 1 pages 0-3 in frames 0-3 except page 5 in frame 2... ");
  815.     for (loop = 0; loop < 4; loop++)
  816.     {
  817.         test_EMMmappage(loop, handle1, loop);
  818.     }
  819.     test_EMMmappage(2, handle1, 5);
  820.     printf("Done.\n");
  821.     printf("Verifying contents... ");
  822.     for (loop = 0; loop < 4; loop++)
  823.     {
  824.         if (farmemcheck(frameptr[loop], 16384,
  825.                                  (unsigned char)((loop != 2) ? loop : 5)) != 0)
  826.         {
  827.             printf("Verify failed for frame %d.\n", loop);
  828.             test_EMMfree(handle1);
  829.             test_EMMfree(handle2);
  830.             exit(3);
  831.         }
  832.     }
  833.     printf("OK.\n");
  834.     TESTTAILER();
  835.  
  836.     TESTHEADER();
  837.     printf("Final mapping test... two handles at once!\n");
  838.     printf("Mapping handle2 page 1 in frame 0.\n");
  839.     printf("        handle1 page 4 in frame 1.\n");
  840.     printf("        handle1 page 0 in frame 2.\n");
  841.     printf("        handle2 page 0 in frame 3.\n");
  842.     test_EMMmappage(0, handle2, 1);
  843.     test_EMMmappage(1, handle1, 4);
  844.     test_EMMmappage(2, handle1, 0);
  845.     test_EMMmappage(3, handle2, 0);
  846.     printf("Mapping done. Verifying... ");
  847.     if (farmemcheck(frameptr[0], 16384, 0x11) != 0)
  848.     {
  849.         printf("Verify failed for frame 0.\n");
  850.         test_EMMfree(handle1);
  851.         test_EMMfree(handle2);
  852.         exit(3);
  853.     }
  854.     if (farmemcheck(frameptr[1], 16384, 4) != 0)
  855.     {
  856.         printf("Verify failed for frame 1.\n");
  857.         test_EMMfree(handle1);
  858.         test_EMMfree(handle2);
  859.         exit(3);
  860.     }
  861.     if (farmemcheck(frameptr[2], 16384, 0) != 0)
  862.     {
  863.         printf("Verify failed for frame 2.\n");
  864.         test_EMMfree(handle1);
  865.         test_EMMfree(handle2);
  866.         exit(3);
  867.     }
  868.     if (farmemcheck(frameptr[3], 16384, 0x10) != 0)
  869.     {
  870.         printf("Verify failed for frame 3.\n");
  871.         test_EMMfree(handle1);
  872.         test_EMMfree(handle2);
  873.         exit(3);
  874.     }
  875.     printf("OK.\n");
  876.     TESTTAILER();
  877.  
  878.     /* clean up */
  879.     test_EMMfree(handle1);
  880.     test_EMMfree(handle2);
  881.     gblmsg = "";
  882.  
  883.     return;
  884. } /* end of do_map_tests() */
  885.  
  886.  
  887. /***************************************************************************
  888. *   FUNCTION: DO_REALLOC_TESTS                                             *
  889. *                                                                          *
  890. *   DESCRIPTION:                                                           *
  891. *                                                                          *
  892. *       This function tests EMSIF calls EMMrealloc() and EMMreallocpages().*
  893. *       Note that EMMreallocpages() is not tested directly; if EMMrealloc()*
  894. *       works, it is only because EMMreallocpages() (which it uses         *
  895. *       internally) is working.                                            *
  896. *                                                                          *
  897. *   ENTRY:                                                                 *
  898. *                                                                          *
  899. *       Void.                                                              *
  900. *                                                                          *
  901. *   EXIT:                                                                  *
  902. *                                                                          *
  903. *       Void.                                                              *
  904. *                                                                          *
  905. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  906. *                                                                          *
  907. ***************************************************************************/
  908. void do_realloc_tests(void)
  909. {
  910.     unsigned long emsfree, emsfree2;
  911.     int handle;
  912.  
  913.     /* set header */
  914.     gblmsg = "  REALLOC TESTS";
  915.     TESTHEADER();
  916.  
  917.     /* allocate original block */
  918.     handle = test_EMMalloc(55555);
  919.  
  920.     /* map and fill */
  921.     test_EMMmappage(0, handle, 0);
  922.     test_EMMmappage(1, handle, 1);
  923.     test_EMMmappage(2, handle, 2);
  924.     test_EMMmappage(3, handle, 3);
  925.     FMEMSET(frameptr[0], 0, 16384);
  926.     FMEMSET(frameptr[1], 1, 16384);
  927.     FMEMSET(frameptr[2], 2, 16384);
  928.     FMEMSET(frameptr[3], 3, 16384);
  929.  
  930.     /* get current value for free EMS */
  931.     emsfree = test_EMMcoreleft();
  932.  
  933.     /* realloc */
  934.     printf("Testing EMMrealloc() to make block shorter.\n");
  935.     handle = test_EMMrealloc(handle, 48000);
  936.  
  937.     /* check free -- should be 16K higher */
  938.     emsfree2 = test_EMMcoreleft();
  939.     if ((emsfree + 16384L) != emsfree2)
  940.     {
  941.         printf("EMMrealloc() should have freed up one page. Old: %lu, new: %lu\n",
  942.                emsfree, emsfree2);
  943.         EMMfree(handle);
  944.         exit(3);
  945.     }
  946.  
  947.     /* check page contents */
  948.     test_EMMmappage(0, handle, 0);
  949.     test_EMMmappage(1, handle, 1);
  950.     test_EMMmappage(2, handle, 2);
  951.     if ((farmemcheck(frameptr[0], 16384, 0) != 0) ||
  952.         (farmemcheck(frameptr[1], 16384, 1) != 0) ||
  953.         (farmemcheck(frameptr[2], 16384, 2) != 0))
  954.     {
  955.         printf("EMMrealloc() did not preserve contents.\n");
  956.         EMMfree(handle);
  957.         exit(3);
  958.     }
  959.     TESTTAILER();
  960.  
  961.     TESTHEADER();
  962.     printf("Testing EMMrealloc() to make block longer.\n");
  963.     handle = test_EMMrealloc(handle, 55555);
  964.  
  965.     /* check free -- should be same as original */
  966.     emsfree2 = test_EMMcoreleft();
  967.     if (emsfree != emsfree2)
  968.     {
  969.         printf("EMMrealloc() did not allocate as expected.\n");
  970.         EMMfree(handle);
  971.         exit(3);
  972.     }
  973.  
  974.     /*
  975.     ** check page contents -- contents of new page are undefined so
  976.     ** don't bother checking it.
  977.     */
  978.     test_EMMmappage(0, handle, 0);
  979.     test_EMMmappage(1, handle, 1);
  980.     test_EMMmappage(2, handle, 2);
  981.     if ((farmemcheck(frameptr[0], 16384, 0) != 0) ||
  982.         (farmemcheck(frameptr[1], 16384, 1) != 0) ||
  983.         (farmemcheck(frameptr[2], 16384, 2) != 0))
  984.     {
  985.         printf("EMMrealloc() did not preserve contents.\n");
  986.         EMMfree(handle);
  987.         exit(3);
  988.     }
  989.     TESTTAILER();
  990.  
  991.     /* clean up */
  992.  
  993.     test_EMMfree(handle);
  994.     gblmsg = "";
  995.  
  996.     return;
  997. } /* end of do_realloc_tests() */
  998.  
  999.  
  1000. /***************************************************************************
  1001. *   FUNCTION: DO_SR_TESTS                                                  *
  1002. *                                                                          *
  1003. *   DESCRIPTION:                                                           *
  1004. *                                                                          *
  1005. *       This function tests the EMSIF mapping save/restore functions:      *
  1006. *       EMMsrinit(), EMMsave(), EMMrestore().                              *
  1007. *                                                                          *
  1008. *   ENTRY:                                                                 *
  1009. *                                                                          *
  1010. *       Void.                                                              *
  1011. *                                                                          *
  1012. *   EXIT:                                                                  *
  1013. *                                                                          *
  1014. *       Void.                                                              *
  1015. *                                                                          *
  1016. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1017. *                                                                          *
  1018. ***************************************************************************/
  1019. void do_sr_tests(void)
  1020. {
  1021.     void *savehandle;
  1022.     int handle1, handle2;
  1023.     int status;
  1024.     int loop;
  1025.  
  1026.     /* set header */
  1027.     gblmsg = "  SAVE/RESTORE TESTS";
  1028.  
  1029.     /* first, allocate some EMS and fill with unique patterns */
  1030.     handle1 = test_EMMallocpages(6);
  1031.     handle2 = test_EMMallocpages(2);
  1032.     for (loop = 0; loop < 6; loop++)
  1033.     {
  1034.         test_EMMmappage(0, handle1, loop);
  1035.         FMEMSET(frameptr[0], loop, 16384);
  1036.         if (farmemcheck(frameptr[0], 16384, (unsigned char) loop) != 0)
  1037.         {
  1038.             printf("Verify failed on handle 1, page %d.\n", loop);
  1039.             test_EMMfree(handle1);
  1040.             test_EMMfree(handle2);
  1041.             exit(3);
  1042.         }
  1043.     }
  1044.     test_EMMmappage(0, handle2, 0);
  1045.     FMEMSET(frameptr[0], 0x10, 16384);
  1046.     if (farmemcheck(frameptr[0], 16384, 0x10) != 0)
  1047.     {
  1048.         printf("Verify failed on handle 2, page 0!\n");
  1049.         test_EMMfree(handle1);
  1050.         test_EMMfree(handle2);
  1051.         exit(3);
  1052.     }
  1053.     test_EMMmappage(0, handle2, 1);
  1054.     FMEMSET(frameptr[0], 0x11, 16384);
  1055.     if (farmemcheck(frameptr[0], 16384, 0x11) != 0)
  1056.     {
  1057.         printf("Verify failed on handle 2, page 1!\n");
  1058.         test_EMMfree(handle1);
  1059.         test_EMMfree(handle2);
  1060.         exit(3);
  1061.     }
  1062.  
  1063.     TESTHEADER();
  1064.     printf(
  1065.      "Testing save/restore facility. Calling EMMsave() before EMMsrinit().\n");
  1066.     printf("Should fail.\n");
  1067.     savehandle = EMMsave();
  1068.     nofailcheck("EMMsave()", (int) _EMMerror, NULL, handle1, handle2);
  1069.     weirdcodechk("EMMsave()", EMM_NOSR, NULL, handle1, handle2);
  1070.     printf("EMMsave() failed OK.\n");
  1071.     TESTTAILER();
  1072.  
  1073.     TESTHEADER();
  1074.     printf("Calling EMMsrinit().\nShould %s.\n",
  1075.                                  ((_EMMversion >= 0x32) ? "succeed" : "fail"));
  1076.     status = EMMsrinit(malloc);
  1077.     if (_EMMversion >= 0x32)
  1078.     {
  1079.         TRIPLECHECK("EMMsrinit()", status, 0, NULL, handle1, handle2);
  1080.         printf("EMMsrinit() succeeded; save/restore facility initialized.\n");
  1081.     }
  1082.     else
  1083.     {
  1084.         weirdretchk("EMMsrinit()", status, NULL, handle1, handle2);
  1085.         nofailcheck("EMMsrinit()", status, NULL, handle1, handle2);
  1086.         weirdcodechk("EMMsrinit()", EMM_BADVERS, NULL, handle1, handle2);
  1087.         printf("EMMsrinit() failed OK. Skipping other save/restore tests.\n");
  1088.     }
  1089.     TESTTAILER();
  1090.  
  1091.     if (_EMMversion >= 0x32)
  1092.     {
  1093.         TESTHEADER();
  1094.         printf("Testing EMMsave().\n");
  1095.         printf("Mapping handle 1 pages 0-3 in frames 0-3 respectively.\n");
  1096.         for (loop = 0; loop < 4; loop++)
  1097.         {
  1098.             test_EMMmappage(loop, handle1, loop);
  1099.         }
  1100.  
  1101.         printf("Calling EMMsave() to save current configuration.\n");
  1102.         printf("Should succeed.\n");
  1103.         savehandle = (void *) NULL;
  1104.         savehandle = EMMsave();
  1105.         if (savehandle == (void *) NULL)
  1106.         {
  1107.             printf("EMMsave() did not return anything, code 0x%X.\n",
  1108.                                                      (unsigned int) _EMMerror);
  1109.             test_EMMfree(handle1);
  1110.             test_EMMfree(handle2);
  1111.             exit(3);
  1112.         }
  1113.         weirdcodechk("EMMsave()", 0, NULL, handle1, handle2);
  1114.         printf("EMMsave() succeeded.\n");
  1115.         TESTTAILER();
  1116.  
  1117.         printf("Changing configuration.\n");
  1118.         test_EMMmappage(0, handle2, 1);
  1119.         test_EMMmappage(1, handle1, 4);
  1120.         test_EMMmappage(2, handle1, 0);
  1121.         test_EMMmappage(3, handle2, 0);
  1122.  
  1123.         TESTHEADER();
  1124.         printf("Calling EMMrestore() to restore previous configuration.\n");
  1125.         printf("Should succeed.\n");
  1126.         status = EMMrestore(savehandle);
  1127.         TRIPLECHECK("EMMrestore()", status, 0, NULL, handle1, handle2);
  1128.         printf("EMMrestore() returned OK, verifying contents... ");
  1129.         for (loop = 0; loop < 4; loop++)
  1130.         {
  1131.             if (farmemcheck(frameptr[loop], 16384, (unsigned char) loop) != 0)
  1132.             {
  1133.                 printf("Verify failed for frame %d.\n", loop);
  1134.                 test_EMMfree(handle1);
  1135.                 test_EMMfree(handle2);
  1136.                 exit(3);
  1137.             }
  1138.         }
  1139.         printf("OK.\n");
  1140.         TESTTAILER();
  1141.     }
  1142.  
  1143.     printf("Cleaning up.\n");
  1144.     test_EMMfree(handle1);
  1145.     test_EMMfree(handle2);
  1146.     if (_EMMversion >= 0x32)
  1147.     {
  1148.         free(savehandle);
  1149.     }
  1150.     gblmsg = "";
  1151.  
  1152.     return;
  1153. } /* end of do_sr_tests() */
  1154.  
  1155. #endif /* !PASS3 */
  1156. #endif /* !PASS2 */
  1157.  
  1158.  
  1159. /*
  1160. ** The following group of functions {test_EMM*()} are wrapper functions
  1161. ** that call the EMSIF function named and perform preliminary checks on
  1162. ** the return values. This keeps code size down since the check only has
  1163. ** to be coded in one place.
  1164. */
  1165.  
  1166. /***************************************************************************
  1167. *   FUNCTION: TEST_EMMCORELEFT                                             *
  1168. *                                                                          *
  1169. *   DESCRIPTION:                                                           *
  1170. *                                                                          *
  1171. *       This function calls EMSIF function EMMcoreleft() and checks the    *
  1172. *       return value to see if it is a multiple of 16384 (the EMS page     *
  1173. *       size).                                                             *
  1174. *                                                                          *
  1175. *   ENTRY:                                                                 *
  1176. *                                                                          *
  1177. *       Void.                                                              *
  1178. *                                                                          *
  1179. *   EXIT:                                                                  *
  1180. *                                                                          *
  1181. *       Returns the value returned by EMMcoreleft().                       *
  1182. *                                                                          *
  1183. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1184. *                                                                          *
  1185. ***************************************************************************/
  1186. unsigned long test_EMMcoreleft(void)
  1187. {
  1188.     unsigned long emsfree;
  1189.  
  1190.     /* call EMMcoreleft and check error code */
  1191.     emsfree = EMMcoreleft();
  1192.     weirdcodechk("EMMcoreleft()", 0, NULL, 0, 0);
  1193.  
  1194.     /* check if free byte count is multiple of 16384 */
  1195.     if ((emsfree % 16384L) != 0)
  1196.     {
  1197.         printf("EMMcoreleft() returned strange number %lu.\n", emsfree);
  1198.         exit(3);
  1199.     }
  1200.  
  1201.     return emsfree;
  1202. } /* end of test_EMMcoreleft() */
  1203.  
  1204.  
  1205. /***************************************************************************
  1206. *   FUNCTION: TEST_EMMALLOC                                                *
  1207. *                                                                          *
  1208. *   DESCRIPTION:                                                           *
  1209. *                                                                          *
  1210. *       This function calls EMSIF function EMMalloc() and checks the       *
  1211. *       return codes.                                                      *
  1212. *                                                                          *
  1213. *   ENTRY:                                                                 *
  1214. *                                                                          *
  1215. *       bytes - bytes of EMS to allocate                                   *
  1216. *                                                                          *
  1217. *   EXIT:                                                                  *
  1218. *                                                                          *
  1219. *       Returns the handle returned by EMMalloc().                         *
  1220. *                                                                          *
  1221. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1222. *                                                                          *
  1223. ***************************************************************************/
  1224. int test_EMMalloc(unsigned long bytes)
  1225. {
  1226.     int handle;
  1227.  
  1228.     /* call EMMalloc() and check the return */
  1229.     handle = EMMalloc(bytes);
  1230.     weirdcodechk("EMMalloc()", 0, NULL, 0, 0);
  1231.  
  1232.     return handle;
  1233. } /* end of test_EMMalloc() */
  1234.  
  1235.  
  1236. /***************************************************************************
  1237. *   FUNCTION: TEST_EMMALLOCPAGES                                           *
  1238. *                                                                          *
  1239. *   DESCRIPTION:                                                           *
  1240. *                                                                          *
  1241. *       This function calls EMSIF function EMMallocpages() and checks the  *
  1242. *       return codes.                                                      *
  1243. *                                                                          *
  1244. *   ENTRY:                                                                 *
  1245. *                                                                          *
  1246. *       pages - pages of EMS to allocate                                   *
  1247. *                                                                          *
  1248. *   EXIT:                                                                  *
  1249. *                                                                          *
  1250. *       Returns the handle returned by EMMallocpages().                    *
  1251. *                                                                          *
  1252. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1253. *                                                                          *
  1254. ***************************************************************************/
  1255. int test_EMMallocpages(int pages)
  1256. {
  1257.     int handle;
  1258.  
  1259.     /* call EMMallocpages() and check the return */
  1260.     handle = EMMallocpages(pages);
  1261.     weirdcodechk("EMMallocpages()", 0, NULL, 0, 0);
  1262.  
  1263.     return handle;
  1264. } /* end of test_EMMallocpages() */
  1265.  
  1266.  
  1267. /***************************************************************************
  1268. *   FUNCTION: TEST_EMMREALLOC                                              *
  1269. *                                                                          *
  1270. *   DESCRIPTION:                                                           *
  1271. *                                                                          *
  1272. *       This function calls EMSIF function EMMrealloc() and checks the     *
  1273. *       return codes.                                                      *
  1274. *                                                                          *
  1275. *   ENTRY:                                                                 *
  1276. *                                                                          *
  1277. *       handle - EMS handle to be resized                                  *
  1278. *       bytes  - new size for handle                                       *
  1279. *                                                                          *
  1280. *   EXIT:                                                                  *
  1281. *                                                                          *
  1282. *       Returns the handle returned by EMMrealloc().                       *
  1283. *                                                                          *
  1284. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1285. *                                                                          *
  1286. ***************************************************************************/
  1287. int test_EMMrealloc(int handle, unsigned long bytes)
  1288. {
  1289.     int newhan;
  1290.  
  1291.     /* call EMMrealloc() and check the return */
  1292.     newhan = EMMrealloc(handle, bytes);
  1293.     weirdcodechk("EMMrealloc()", 0, NULL, handle, newhan);
  1294.     if (((_EMMversion >= 0x40) && (newhan != handle)) ||
  1295.         ((_EMMversion < 0x40) && (newhan == handle)))
  1296.     {
  1297.         printf("Handle problem in EMMrealloc(). New: %d, old: %d\n", newhan,
  1298.                handle);
  1299.         EMMfree(handle);
  1300.         EMMfree(newhan);
  1301.     }
  1302.  
  1303.     return newhan;
  1304. } /* end of test_EMMrealloc() */
  1305.  
  1306.  
  1307. /***************************************************************************
  1308. *   FUNCTION: TEST_EMMFREE                                                 *
  1309. *                                                                          *
  1310. *   DESCRIPTION:                                                           *
  1311. *                                                                          *
  1312. *       This function calls EMSIF function EMMfree() and checks the        *
  1313. *       return codes.                                                      *
  1314. *                                                                          *
  1315. *   ENTRY:                                                                 *
  1316. *                                                                          *
  1317. *       handle - EMS handle to be freed                                    *
  1318. *                                                                          *
  1319. *   EXIT:                                                                  *
  1320. *                                                                          *
  1321. *       Void.                                                              *
  1322. *                                                                          *
  1323. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1324. *                                                                          *
  1325. ***************************************************************************/
  1326. void test_EMMfree(int handle)
  1327. {
  1328.     int status;
  1329.  
  1330.     /* call EMMfree() and check the return */
  1331.     status = EMMfree(handle);
  1332.     TRIPLECHECK("EMMfree()", status, 0, NULL, 0, 0);
  1333.  
  1334.     return;
  1335. } /* end of test_EMMfree() */
  1336.  
  1337.  
  1338. /***************************************************************************
  1339. *   FUNCTION: TEST_EMMMAPPAGE                                              *
  1340. *                                                                          *
  1341. *   DESCRIPTION:                                                           *
  1342. *                                                                          *
  1343. *       This function calls EMSIF function EMMmappage() and checks the     *
  1344. *       return codes.                                                      *
  1345. *                                                                          *
  1346. *   ENTRY:                                                                 *
  1347. *                                                                          *
  1348. *       frameno - frame number to map page into                            *
  1349. *       handle  - handle of page to be mapped                              *
  1350. *       logpage - page number to map                                       *
  1351. *                                                                          *
  1352. *   EXIT:                                                                  *
  1353. *                                                                          *
  1354. *       Void.                                                              *
  1355. *                                                                          *
  1356. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1357. *                                                                          *
  1358. ***************************************************************************/
  1359. void test_EMMmappage(int frameno, int handle, int logpage)
  1360. {
  1361.     int status;
  1362.  
  1363.     /*
  1364.     ** do sanity check on frame number, just in case -- we shouldn't be
  1365.     ** trying to map into frames other than standard 0 through 3.
  1366.     */
  1367.     if ((frameno < 0) || (frameno > 3))
  1368.     {
  1369.         printf("Sanity check failed, trying to map to frame %d, aborting.\n",
  1370.                                                                       frameno);
  1371.         EMMfree(handle);
  1372.         exit(3);
  1373.     }
  1374.  
  1375.     /* call EMMmappage() and check return */
  1376.     status = EMMmappage(frameno, handle, logpage);
  1377.     TRIPLECHECK("EMMmappage()", status, 0, NULL, handle, 0);
  1378.  
  1379.     return;
  1380. } /* end of test_EMMmappage() */
  1381.  
  1382.  
  1383. /*
  1384. ** The following group of functions are used to speed up return checking
  1385. ** and keep code size down, since the return check only has to be coded
  1386. ** in one place. They are used in various macros to further compact and
  1387. ** clarify the code.
  1388. */
  1389.  
  1390. /***************************************************************************
  1391. *   FUNCTION: WEIRDRETCHK                                                  *
  1392. *                                                                          *
  1393. *   DESCRIPTION:                                                           *
  1394. *                                                                          *
  1395. *       This function checks to see if the status value passed to it is    *
  1396. *       either 0 or EMMOOPS, and assumes something has gone wrong if it    *
  1397. *       is not. If something has gone wrong, does some clean up before     *
  1398. *       exiting.                                                           *
  1399. *                                                                          *
  1400. *   ENTRY:                                                                 *
  1401. *                                                                          *
  1402. *       function - name of function which may have goofed                  *
  1403. *       status   - status value to check                                   *
  1404. *       tofree1  - conventional memory block to be freed on exit. Not      *
  1405. *                  freed if NULL.                                          *
  1406. *       tofree2  - EMS handle to be freed on exit. Not freed if 0.         *
  1407. *       tofree2  - another EMS handle to be freed on exit. Not freed if 0. *
  1408. *                                                                          *
  1409. *   EXIT:                                                                  *
  1410. *                                                                          *
  1411. *       Void, or may not return.                                           *
  1412. *                                                                          *
  1413. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1414. *                                                                          *
  1415. ***************************************************************************/
  1416. void weirdretchk(char *function, int status, void *tofree1, int tofree2,
  1417.                                                                    int tofree3)
  1418. {
  1419.     if ((status != EMMOOPS) && (status != 0))
  1420.     {
  1421.         printf("%s returned weird value %d, code 0x%X.\n", function, status,
  1422.                                                      (unsigned int) _EMMerror);
  1423.         if (tofree1 != (void *) NULL)
  1424.         {
  1425.             free(tofree1);
  1426.         }
  1427.         if (tofree2 != 0)
  1428.         {
  1429.             EMMfree(tofree2);
  1430.         }
  1431.         if (tofree3 != 0)
  1432.         {
  1433.             EMMfree(tofree3);
  1434.         }
  1435.         exit(3);
  1436.     }
  1437.  
  1438.     return;
  1439. } /* end of weirdretchk() */
  1440.  
  1441.  
  1442. /***************************************************************************
  1443. *   FUNCTION: WEIRDCODECHK                                                 *
  1444. *                                                                          *
  1445. *   DESCRIPTION:                                                           *
  1446. *                                                                          *
  1447. *       This function checks to see if the EMSIF error code value matches  *
  1448. *       the expected value, and assumes something has gone wrong if it     *
  1449. *       does not. If something has gone wrong, does some clean up before   *
  1450. *       exiting.                                                           *
  1451. *                                                                          *
  1452. *   ENTRY:                                                                 *
  1453. *                                                                          *
  1454. *       function - name of function which may have goofed                  *
  1455. *       expected - expected value of _EMMerror                             *
  1456. *       tofree1  - conventional memory block to be freed on exit. Not      *
  1457. *                  freed if NULL.                                          *
  1458. *       tofree2  - EMS handle to be freed on exit. Not freed if 0.         *
  1459. *       tofree2  - another EMS handle to be freed on exit. Not freed if 0. *
  1460. *                                                                          *
  1461. *   EXIT:                                                                  *
  1462. *                                                                          *
  1463. *       Void, or may not return.                                           *
  1464. *                                                                          *
  1465. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1466. *                                                                          *
  1467. ***************************************************************************/
  1468. void weirdcodechk(char *function, int expected, void *tofree1, int tofree2,
  1469.                                                                    int tofree3)
  1470. {
  1471.     if ((int) _EMMerror != expected)
  1472.     {
  1473.         printf("%s returned unexpected code 0x%X.\n", function,
  1474.                                                      (unsigned int) _EMMerror);
  1475.         if (tofree1 != (void *) NULL)
  1476.         {
  1477.             free(tofree1);
  1478.         }
  1479.         if (tofree2 != 0)
  1480.         {
  1481.             EMMfree(tofree2);
  1482.         }
  1483.         if (tofree3 != 0)
  1484.         {
  1485.             EMMfree(tofree3);
  1486.         }
  1487.         exit(3);
  1488.     }
  1489.  
  1490.     return;
  1491. } /* end of weirdcodechk() */
  1492.  
  1493.  
  1494. /***************************************************************************
  1495. *   FUNCTION: FAILCHECK                                                    *
  1496. *                                                                          *
  1497. *   DESCRIPTION:                                                           *
  1498. *                                                                          *
  1499. *       This function checks to see if the status value passed to it is    *
  1500. *       EMMOOPS and exits if it is. failcheck() is used when a function    *
  1501. *       is expected to succeed. Does some clean up before exiting.         *
  1502. *                                                                          *
  1503. *   ENTRY:                                                                 *
  1504. *                                                                          *
  1505. *       function - name of function which may have goofed                  *
  1506. *       status   - status value to be checked                              *
  1507. *       tofree1  - conventional memory block to be freed on exit. Not      *
  1508. *                  freed if NULL.                                          *
  1509. *       tofree2  - EMS handle to be freed on exit. Not freed if 0.         *
  1510. *       tofree2  - another EMS handle to be freed on exit. Not freed if 0. *
  1511. *                                                                          *
  1512. *   EXIT:                                                                  *
  1513. *                                                                          *
  1514. *       Void, or may not return.                                           *
  1515. *                                                                          *
  1516. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1517. *                                                                          *
  1518. ***************************************************************************/
  1519. void failcheck(char *function, int status, void *tofree1, int tofree2,
  1520.                                                                   int tofree3)
  1521. {
  1522.     if (status == EMMOOPS)
  1523.     {
  1524.         printf("%s failed, code 0x%X.\n", function, (unsigned int) _EMMerror);
  1525.         if (tofree1 != (void *) NULL)
  1526.         {
  1527.             free(tofree1);
  1528.         }
  1529.         if (tofree2 != 0)
  1530.         {
  1531.             EMMfree(tofree2);
  1532.         }
  1533.         if (tofree3 != 0)
  1534.         {
  1535.             EMMfree(tofree3);
  1536.         }
  1537.         exit(3);
  1538.     }
  1539.  
  1540.     return;
  1541. } /* end of failcheck() */
  1542.  
  1543.  
  1544. /***************************************************************************
  1545. *   FUNCTION: NOFAILCHECK                                                  *
  1546. *                                                                          *
  1547. *   DESCRIPTION:                                                           *
  1548. *                                                                          *
  1549. *       This function checks to see if the status value passed to it is    *
  1550. *       0 and exits if it is. nofailcheck() is used when a function is     *
  1551. *       expected to fail. Does some clean up before exiting.               *
  1552. *                                                                          *
  1553. *   ENTRY:                                                                 *
  1554. *                                                                          *
  1555. *       function - name of function which may have goofed                  *
  1556. *       status   - status value to be checked                              *
  1557. *       tofree1  - conventional memory block to be freed on exit. Not      *
  1558. *                  freed if NULL.                                          *
  1559. *       tofree2  - EMS handle to be freed on exit. Not freed if 0.         *
  1560. *       tofree2  - another EMS handle to be freed on exit. Not freed if 0. *
  1561. *                                                                          *
  1562. *   EXIT:                                                                  *
  1563. *                                                                          *
  1564. *       Void, or may not return.                                           *
  1565. *                                                                          *
  1566. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1567. *                                                                          *
  1568. ***************************************************************************/
  1569. void nofailcheck(char *function, int status, void *tofree1, int tofree2,
  1570.                                                                   int tofree3)
  1571. {
  1572.     if (status == 0)
  1573.     {
  1574.         printf("%s did not fail.\n", function);
  1575.         if (tofree1 != (void *) NULL)
  1576.         {
  1577.             free(tofree1);
  1578.         }
  1579.         if (tofree2 != 0)
  1580.         {
  1581.             EMMfree(tofree2);
  1582.         }
  1583.         if (tofree3 != 0)
  1584.         {
  1585.             EMMfree(tofree3);
  1586.         }
  1587.         exit(3);
  1588.     }
  1589.  
  1590.     return;
  1591. } /* end of nofailcheck() */
  1592.  
  1593.